package com.neu.servlet.klz;

import com.alibaba.fastjson.JSONObject;
import com.neu.service.klz.EventDaoService;
import com.neu.service.klz.KindDaoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "AddFindByNameServlet", urlPatterns = {"/AddFindByNameServlet.do"})
public class AddFindByNameServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        EventDaoService eventDaoService=new EventDaoService();
        List<Map<String,Object>>list=eventDaoService.dofindByEname();
        HttpSession session=request.getSession();
        session.setAttribute("kinds",list);
        KindDaoService kindDaoService=new KindDaoService();
        List<Map<String,Object>>list1=kindDaoService.dofindByKname();
        HttpSession session1=request.getSession();
        session.setAttribute("events",list1);
        JSONObject data=new JSONObject();
        if (list.size()>0&&list1.size()>0){
            data.put("success","success");
        }else {
            data.put("fail","fail");
        }
        PrintWriter out=response.getWriter();
        out.println(data.toString());
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
